package com.example.ai.test;

import org.springframework.ai.converter.BeanOutputConverter;
import org.springframework.ai.converter.ListOutputConverter;
import org.springframework.ai.converter.MapOutputConverter;
import org.springframework.ai.document.Document;
import org.springframework.ai.reader.JsonReader;
import org.springframework.core.convert.support.DefaultConversionService;
import org.springframework.core.io.ClassPathResource;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class Test {



    public static void main(String[] args) {
        /*JsonReader jsonReader = new JsonReader(new ClassPathResource("goods.json"));
        // 修改: 使用正确的 JSON Pointer 表达式来访问第一个元素的 price 值
        List<Document> documents = jsonReader.get("/0/price");
        if (!documents.isEmpty()) {
            Document firstDocument = documents.get(0);
            String price = firstDocument.getText();
            System.out.println(price);
        } else {
            System.out.println("No documents found.");
        }*/

        // ???????? https://docs.spring.io/spring-ai/reference/1.0/api/etl-pipeline.html#_example_json_structure
        /*JsonReader jsonReader = new JsonReader(new ClassPathResource("bikes.json"));
        List<Document> documents = jsonReader.get("/0/brand");
        System.out.println(documents);*/


        BeanOutputConverter beanOutputConverter = new BeanOutputConverter(Person.class);
        System.out.println(beanOutputConverter.getFormat());

        BeanOutputConverter beanOutputConverter2 = new BeanOutputConverter(List.class);
        System.out.println(beanOutputConverter2.getFormat());

        MapOutputConverter mapOutputConverter = new MapOutputConverter();
        System.out.println(mapOutputConverter.getFormat());

        DefaultConversionService defaultConversionService = new DefaultConversionService();
        ListOutputConverter listOutputConverter = new ListOutputConverter(defaultConversionService);
        System.out.println(listOutputConverter.getFormat());
    }

    record Person(String name, int age){

    }
}